import matplotlib.pyplot as plt
import pandas as pd

# 设置matplotlib支持中文显示
plt.rcParams['font.sans-serif'] = ['SimHei']  # 使用黑体
plt.rcParams['axes.unicode_minus'] = False  # 正确显示负号

# 假设这是过去几年的关键财务数据
data = {
    'Year': ['2020', '2021', '2022', '2023'],
    'Revenue (Billion Yuan)': [23.39, 26.50, 27.65, 25.09],
    'Net Profit (Billion Yuan)': [13.27, 12.70, 9.88, 24.48],
    'Total Assets (Billion Yuan)': [18.68, 19.83, 21.78, 23.84],
    'Debt Ratio (%)': [39.85, 39.75, 40.00, 35.18]
}

# 转换为DataFrame
df = pd.DataFrame(data)

# 绘制营业收入、净利润、总资产的变化趋势
plt.figure(figsize=(10, 6))
plt.plot(df['Year'], df['Revenue (Billion Yuan)'], marker='o', label='Revenue')
plt.plot(df['Year'], df['Net Profit (Billion Yuan)'], marker='s', label='Net Profit')
plt.plot(df['Year'], df['Total Assets (Billion Yuan)'], marker='^', label='Total Assets')
plt.title('Key Financial Indicators Trend')
plt.xlabel('Year')
plt.ylabel('Amount (Billion Yuan)')
plt.legend()
plt.grid(True)
plt.show()  # 显示图表

# 绘制负债率的变化
plt.figure(figsize=(10, 6))
plt.bar(df['Year'], df['Debt Ratio (%)'], color='skyblue')
plt.title('Debt Ratio Change')
plt.xlabel('Year')
plt.ylabel('Debt Ratio (%)')
plt.ylim(0, 50)  # 设置y轴的范围
plt.grid(True)
plt.show()  # 显示图表